package dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import model.Placar;
import model.Time;
import interfaces.ITime;

public class DaoTime extends DaoGenerico<Time> implements ITime{

	@Override
	public Time getPorId(Long id) {
		Session session = this.getSession();
		Criteria criteria = session.createCriteria(Time.class);
		criteria.add(Restrictions.eq("id", id));
		Time t = (Time) criteria.uniqueResult();
		session.close();
		return t;
	}

	@Override
	public Time getTimePorNome(String nome) {
		Session session = this.getSession();
		Criteria criteria = session.createCriteria(Time.class);
		criteria.add(Restrictions.eq("nome", nome));
	    Time t = (Time) criteria.uniqueResult();
		session.close();
		return t;
	}
	
	@Override
	public Time getTimePorPlacar(Placar placar) {
		Session session = this.getSession();
		Criteria criteria = session.createCriteria(Time.class);
		criteria.add(Restrictions.eq("placar", placar));
	    Time t = (Time) criteria.uniqueResult();
		session.close();
		return t;
	}


}
